/*
 create by sys on 2016/11/22.
 */

define(["require",'config/appregister',"business/Companyinfor/service/htttp","business/services/filter","jquery","business/workSkill/directive/startLevel"],function(require,app,httpServices){
    app.controller('comPanyBlogCtrl',function($scope,$timeout,$stateParams,$state,auth){
        auth.isCompanyLogin();
        $scope.headerLink=function(){
            $state.go("myMainPage")
        }
		
		if($stateParams.comPanyBlogId) {
            var blogId = $stateParams.comPanyBlogId;
            function getBwDetail(blogId) {
                var req = {
                    type: 'GET',
                    uri: 'getInfo',
                    data: {
                        blogId: blogId,
                        type: '1'
                    }
                };
                httpServices.bwHttpService(req).success(function (response) {
                    if (!response.data) return;
                    $scope.$apply(function () {
                        if (response.data.fpre == null) {
                            $scope.preBlog = "没有上一篇了";
                        } else {
                            $scope.preBlog = response.data.fpre.title;
                        }
                        if (response.data.fnext == null) {
                            $scope.nextBlog = "没有下一篇了";
                        } else {
                            $scope.nextBlog = response.data.fnext.title;
                        }
                        if (response.data.blog.flag) {
                            $scope.collect = "已收藏";
                        } else {
                            $scope.collect = "收藏"
                        }
                        $scope.fnext = response.data.fnext;
                        $scope.fpre = response.data.fpre;
                        $scope.blogDetail = response.data.blog;
                        $("#blogCons").append(response.data.blog.introduction);
                        $scope.blogTags = response.data.blog.labelList;

                    })
                }).error(function (response) {

                })
            }

            getBwDetail(blogId);
            //获取其他博文
            function getOtherBlog(blogId) {
                var req = {
                    type: 'GET',
                    uri: 'getOtherBlog',
                    data: {
                        pageNo: '1',
                        pageSize: '10',
                        all: 'false',
                        blogId: blogId,
                        //userId: '11',
                        type: '1'
                    }
                };
                httpServices.bwHttpService(req).success(function (response) {
                    if (!response.data) return;
                    $scope.$apply(function () {
                        $scope.otherBlog = response.data.list;
                    })
                }).error(function (response) {

                })
            }

            getOtherBlog(blogId);
            //获取热门博文
            function getHotBlog() {
                var req = {
                    type: 'GET',
                    uri: 'getGreetBlog',
                    data: {
                        count: '10',
                        type: '1'
                    }
                };
                httpServices.bwHttpService(req).success(function (response) {
                    if (!response.data) return;
                    $scope.$apply(function () {
                        $scope.hotBlog = response.data;
                    })
                }).error(function (response) {

                })
            }

            getHotBlog();
            //获取谁看过我的博文
            function getMark(blogId) {
                var req = {
                    type: 'GET',
                    uri: 'getMark',
                    data: {
                        fkId: blogId,
                        type: '1'
                    }
                };
                httpServices.bwHttpService(req).success(function (response) {
                    if (!response.data) return;
                    $scope.$apply(function () {
                        $scope.getMark = response.data;
                        $scope.getMark.length = $scope.getMark.length <= 8 ? $scope.getMark.length : 8;
                    })
                }).error(function (response) {

                })
            }

            getMark(blogId);
            //进入上一篇博文，下一篇博文和其他博文
            $scope.goOtherBlog = function (blogId) {
                getBwDetail(blogId);
                getOtherBlog(blogId);
                getMark(blogId);
            }
            //进入博文详情
            $scope.goBlogDetail = function (blogId) {
                getBwDetail(blogId);
                getOtherBlog(blogId);
                getMark(blogId);
                $scope.bwdetail = 2;
                $scope.bTag = 4;
            }
            $scope.hideCon=function(){
                $scope.showHIde=2;
            }
            $scope.hideSure=function(){
                $scope.showHIde=2;
            }
            $scope.DeleteBlog=function(){
                $scope.showHIde=1;
            }
            $scope.DeleteCompanyBlgo = function () {
                var req = {
                    type: "GET",
                    uri: "del",
                    data: {
                        blogid: $stateParams.comPanyBlogId
                    }
                };
                httpServices.getBlog(req).success(function (response) {
                    $scope.$apply(function () {
                        $scope.showHIde=2;
                        $state.go('comIndexCtrl.resource')
                        $scope.ResourceTab=2;
                    })
                });
            }
            $scope.modeBlog=function(){
                $state.go("blogmod",{blogid:$stateParams.comPanyBlogId,blogType:1})
            }


        }

			

    })
});
